﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Portal.Common.Interface;
using Common.Service;
using System.Collections;

namespace Portal
{
    public partial class SystemLog : System.Web.UI.Page
    {
        ISystemLog _systemLogService;

        public ISystemLog SystemLogService
        {
            get {
                if (_systemLogService == null)
                {
                    _systemLogService = ServiceContainer.GetService<ISystemLog>();
                }
                return _systemLogService; }
            set { _systemLogService = value; }
        }
        private int _start = 0;
        private int _limit = 10;
        protected void Page_Load(object sender, EventArgs e)
        {
            _start = int.Parse(_StartRow.Value);
            if (!IsPostBack)
            {
                LogDataBindding();
            }
        }

        private void LogDataBindding()
        {
            int count = 0;
            IList systemLogs = SystemLogService.GetList("SystemLogLogic_GetList", _start, _limit, out count);
            if (systemLogs.Count == 0)
            {
                return;
            }
            PageDataBindding();
            rptSystemLogList.DataSource = systemLogs;
            rptSystemLogList.DataBind();
        }

        /// <summary>
        /// 当前显示数据在表格中所载行
        /// </summary>
        private void PageDataBindding()
        {
            int count = GetSystemLogCount();
            lblPageRecord.Text = string.Format("{0}-{1}  of  {2}", _start <= 0 ? 0 : _start, (_start + 10) >= count ? count : _start + 10, count);
        }

        /// <summary>
        /// 获取系统日志数量
        /// </summary>
        /// <returns></returns>
        private int GetSystemLogCount()
        {
            int count = 0;
            SystemLogService.GetSystemLogCount("SystemLogLogic_GetList", out count);
            return count;
        }

        protected void FirstPage_Click(object sender, EventArgs e)
        {
            _start = 0;
            _StartRow.Value = "0";
            LogDataBindding();
        }

        protected void UpPage_Click(object sender, EventArgs e)
        {
            if (_start > 0)
            {
                _start = int.Parse(_StartRow.Value) - _limit;
                _StartRow.Value = (int.Parse(_StartRow.Value) - _limit).ToString();
                LogDataBindding();
            }
        }

        protected void DownPage_Click(object sender, EventArgs e)
        {
            _start = int.Parse(_StartRow.Value) + _limit;
            _StartRow.Value = (int.Parse(_StartRow.Value) + _limit).ToString();
            LogDataBindding();
        }

        protected void LastPage_Click(object sender, EventArgs e)
        {
            int count = GetSystemLogCount();
            int page = count / _limit;
            _start = page * _limit;
            _StartRow.Value = (page * _limit).ToString();
            _limit = count % _limit;
            LogDataBindding();
        }
    }
}